package com.lord.otter.component.tools.business.chain;

import lombok.extern.slf4j.Slf4j;


/**
 * 使用单的最顶层抽象的类业务处理器
 */
@Slf4j
public abstract class AbstractBusinessHandler<T, C extends BusinessContextAttributeDefinitionTable> implements BusinessHandler<T, C> {

    private BusinessContext<C> context;


    protected abstract void doHandle(T command);

    @Override
    public void handle(T command, BusinessContext<C> context) {
        this.context = context;
        log.info("业务执行器触发调用,业务执行器的名字:" + getName());
        doHandle(command);
        this.context = null;
    }


    protected <V> V getAttribute(C t) {
        return context.getAttribute(t);
    }

    protected void setAttribute(C t, Object o) {
        context.setAttribute(t, o);
    }

    protected BusinessContext<C> getContext() {
        return context;
    }

}
